<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理学科</title>

    <link href="bootstrap-4.6.1-dist/css/bootstrap.css"
          rel="stylesheet" type="text/css">
    <style>
        .dropdown{
            margin-bottom: -20px;
        }
        .dropdown:hover{
            margin: 0px;
        }
        .userPortrait {
            width: 40px;
            height: 40px;
            border: 1px solid red;
            border-radius: 50%;
            overflow: hidden;
            margin: 0 auto;
            /*margin-top: 100px;*/
        }
        .userPortrait img {
            display: block;
            width: 100%;
            height:100%;
            border: 1px solid green;
        }
        .welcome{
            width: 100%;
            height: 100px;
            float: left;
        }
        .subject{
            margin-top: 60px;
        }

    </style>
</head>
<body>
<!-- Modal -->
<div class="modal fade" id="delModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="delModalLabel">提示</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                您确定要删除【<span id="deluserName"></span>】吗?
                <form id="delForm">
                    <input type="hidden" name="ids" id="deluserId">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick='doDelete()'>确定</button>
            </div>
        </div>
    </div>
</div>
<!--眉头-->
<nav class="nav navbar-expand-lg navbar-dark bg-primary">
    <a class="navbar-brand col-1 text-center" href="index.html" >
        爱思教育
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse
    " data-target="#navbarText" aria-controls="navbarText" aria-expanded="false
    " aria-label="Toggle navigation">
        <span class="navbar-toggler-icon">111</span>
    </button>
    <div class="collapse navbar-collapse">
        <ul class="navbar-nav">
            <li class="nav-item active">
                <a class="nav-link"></a>
            </li>
            <li class="nav-item active">
                <a class="nav-link " href="managerHome.html">
                    点击此处返回管理员主页
                </a>
            </li>

        </ul>
    </div>
    <div class="userPortrait active dropdown">
        <a href="userInformation.html"><img src="img/defaultPortrait.jpg" alt=""></a>
    </div>
</nav>

<!--中间-->
<div class="row">
    <!--侧边栏-->
    <ul class="navbar-nav bg-light text-center col-md-2">
        <li class="nav-item">
            <a class="nav-link btn btn-light" href="#">消息列表</a>
        </li>
    </ul>

    <div  id="main" class="main col-10">
        <div id="top" class="main col-10 welcome">
            <font face="隶书" size="+4" color=black> 管理员你好，欢迎使用用户系统</font>
        </div>
        <div id="center" class="main">
            <form id="form">
                <table>
                    <tr>
                        <td>姓名：</td>
                        <td>
                            <input type="text" class="form-control" name="userName">
                        </td>
                        <td>ID：</td>
                        <td>
                            <input type="text" class="form-control" name="userId">
                        </td>
                        <td>性别：</td>
                        <td>
                            <select name="userSex" class="form-control">
                                <option value="0">查询所有</option>
                                <option value="1">男</option>
                                <option value="2">女</option>
                            </select>
                        </td>
                        <td>职业：</td>
                        <td>
                            <select name="userType" class="form-control">
                                <option value="-1">查询所有</option>
                                <option value="2">教师</option>
                                <option value="3">学生</option>
                            </select>
                        </td>
                        <td>
                            <button id="btnSearch" class="btn btn-primary  align-content-center text-center" type="button" >查询</button>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <div id="bottom" class="main col-10 subject">
            <form id="batchForm">
                <table class="table table-hover table-bordered">
                    <thead class="thead-light">
                    <tr>
                        <th scope="col">姓名</th>
                        <th scope="col">ID</th>
                        <th scope="col">性别</th>
                        <th scope="col">职业</th>
                        <th scope="col">电话</th>
                        <th scope="col">邮箱</th>
                        <th scope="col">操作</th>
                    </tr>
                    </thead>
                    <tbody id="tbody">
                    <tr>
                        <td colspan="7" class="text-center">没有数据</td>
                    </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
    <!--页脚-->
    <div class="footer bg-primary fixed-bottom text-center">
        <p class="text-white">版权所有© Copyright 1999-2021 爱思软件股份有限公司　　中国·青岛黄岛区嘉陵江路777号 西区公寓2号   版本V-0.0.1</p>
    </div>

</div>

</body>
<script src="jquery/jquery-3.6.0.min.js"></script>
<script src="bootstrap-4.6.1-dist/js/bootstrap.min.js"></script>
<script>
    jQuery(function () {
        jQuery("#btnSearch").click(function () {
            init();
        });
    })

</script>
<script>
    function init()
    {
        let form=jQuery("#form").serialize();
        jQuery.post("manager/search_users",form,function (rst) {
            //js中非空即真
            //后台返回String或Map集合
            // if(!rst)
            // {
            //     //rst为空，提示
            // }
            //如果返回list，jquery自动转为数组

            // if(rst.length==0)
            // {
            //
            // }
            let trs='';

            for(let i=0;i<rst.length;i++)
            {
                let u=rst[i];
                trs+=`
                        <tr>
                            <td>${u.userName}</td>
                            <td>${u.userId}</td>
                            <td>${u.userSex==1?'男':(u.userSex==2?'女':'保密')  }</td>
                            <td>${u.userType==2?'教师':(u.userType==3?'学生':'管理员')}</td>
                            <td>${u.userPhone}</td>
                            <td>${u.userEmail}</td>
                            <td>
                                <a href="#" onclick='showDeleteDialog(${JSON.stringify(u)})'>删除</a>
                            </td>
                        </tr>
                    `;
            }
            if(trs.length==0)
            {
                trs=`
                         <tr>
                            <td colspan="7" class="text-center">无相关信息</td>
                        </tr>
                    `;
            }
            //把数据添加到tbody中
            jQuery("#tbody").html(trs);

        })
    }
</script>
<script>
    function showDeleteDialog(user) {
        console.log(user);
        jQuery("#deluserName").html(user.userName);
        jQuery("#deluserId").val(user.userId);
        jQuery("#delModal").modal('show');
    }
    function doDelete() {
        let form=jQuery("#delForm").serialize();
        jQuery.post("manager/Delete_users",form,function (rst) {
            if(rst>0)
            {
                alert("删除成功！");
                init();
            }else{
                alert("删除失败！");
            }
        });
        jQuery("#delModal").modal('hide');
    }
</script>


</html>


